﻿#region references
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/* Project dependencies */
using IcaGames.Logging;
using IcaGames.Database;
using IcaGames.Objects;
using IcaGames.Database.ObjectManagement;
#endregion

public partial class AdvancedSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                /* Get the search results for the search query */
                string searchQuery = Request.QueryString["q"];
                string catQuery = Request.QueryString["cat"];
                
                if (catQuery.Equals("games"))
                {
                    string sizeQuery = Request.QueryString["size"];
                    string platformQuery = Request.QueryString["platform"];

                    List<Game> searchResults = DatabaseStore.GetSearchResults(searchQuery, 
                        sizeQuery, platformQuery);

                    ucSearchResults._gameSearchResults = searchResults.Count.ToString();
                    ucSearchResults._gvGamesDataSource = searchResults;
                    ucSearchResults._mvActiveViewIndex = 0;
                }
                else
                {
                    List<Publisher> searchResults = PublisherManagement.GetPublishers(searchQuery);

                    ucSearchResults._publisherSearchResults = searchResults.Count.ToString();
                    ucSearchResults._gvPublisherDataSource = searchResults;
                    ucSearchResults._mvActiveViewIndex = 1;
                }
            }
            catch (Exception ex)
            {
                Log.CreateLog("Exception while getting QueryString from frontpage", "ADVANCEDSEARCH");
                Log.CreateLog(ex.Message, "ADVANCEDSEARCH");
            }
        }
    }
}
